# -*- coding: utf-8 -*-
from django.core.management import BaseCommand
from apps.oaauth.models import *


class Command(BaseCommand):
    def handle(self, *args, **options):
        boarder = OADepartment.objects.get(name='董事会')
        developer = OADepartment.objects.get(name='产品开发部')
        operator = OADepartment.objects.get(name='运营部')
        saler = OADepartment.objects.get(name='销售部')
        hr = OADepartment.objects.get(name='人事部')
        finance = OADepartment.objects.get(name='财务部')
        # 董事会的员工都是superuser用户
        # 1.东东，董事会leader
        dongdong = OAUser.objects.create_superuser(email='dongdong@qq.com', password='111111', realname='东东',
                                                   department=boarder)
        # 2.多多：董事会
        duoduo = OAUser.objects.create_user(email='duoduo@qq.com', password='111111', realname='多多',
                                            department=boarder)
        # 张三产品开发部leader
        zhangsan = OAUser.objects.create_user(email='zhangsan@qq.com', password='111111', realname='张三',
                                              department=developer)
        # 李四运营部leader
        lisi = OAUser.objects.create_user(email='lisi@qq.com', password='111111', realname='李四',
                                          department=operator)
        # 王五人事部leader
        wangwu = OAUser.objects.create_user(email='wangwu@qq.com', password='111111', realname='王五',
                                            department=hr)
        # 赵六销售部leader
        zhaoliu = OAUser.objects.create_user(email='zhaoliu@qq.com', password='111111', realname='赵六',
                                             department=saler)
        # 孙七财务部leader
        sunqi = OAUser.objects.create_user(email='sunqi@qq.com', password='111111', realname='孙七',
                                           department=finance)
        # 给部门指定leader和manager
        # 东东：产品开发部，运营部，销售部
        # 多多：人事部，财务部
        # 1.董事会
        boarder.leader = dongdong
        boarder.manager = None
        # 2.产品开发部
        operator.leader = zhangsan
        operator.manager = dongdong
        # 运营部
        developer.leader = lisi
        developer.manager = dongdong
        # 销售
        operator.manager = zhaoliu
        operator.leader = dongdong
        # 人事
        operator.manager = wangwu
        operator.leader = duoduo
        # 财务
        finance.manager = sunqi
        finance.leader = duoduo

        boarder.save()
        operator.save()
        developer.save()
        hr.save()
        finance.save()
        saler.save()
        self.stdout.write('初始化用户成功')
